<template>
  <el-dialog title="商品价格组详情" :close-on-click-modal="false" :visible.sync="visible" append-to-body center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form :model="dataForm" ref="dataForm" label-width="80px">
      <el-row>

        <el-col :span="8">
          <el-form-item label="价格组">
            <el-select v-model="dataForm.priceGroupId" disabled>
              <el-option v-for="item in priceGroupOptions" :key="item.value" :value="item.value" :label="item.name"></el-option>
            </el-select>
            <!-- <el-input v-model="dataForm.priceGroupId" placeholder="价格组id"></el-input> -->
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="税率">
            <el-input v-model="dataForm.taxRate" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8"></el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="含税价格">
            <el-input v-model="dataForm.taxPrice" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="无税价格">
            <el-input v-model="dataForm.notTaxPrice" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="零售价格">
            <el-input v-model="dataForm.price" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注" prop="memo">
        <el-input v-model="dataForm.memo" disabled></el-input>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
  import { goodsPriceGetObj, goodsPriceAddObj, goodsPricePutObj } from '@/api/eims/goods-price.js'
  import { priceGroupFetchList } from '@/api/eims/price-group.js'

  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          goodsId: '',
          goodsName: '',
          priceGroupId: '',
          // priceGroupName: '',
          taxRate: '',
          taxPrice: '',
          notTaxPrice: '',
          price: '',
          memo: '',
          status: '1'
        },
        priceGroupOptions: []
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.getPriceGroupList()
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            goodsPriceGetObj(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      // 获取价格组列表
      getPriceGroupList () {
        priceGroupFetchList().then(response => {
          if(response.data.code == '0'){
            let resultData = response.data.data.records
            let list = []
            resultData.forEach(item => {
              list.push({value: item.id,name:item.groupName})
            })
            this.priceGroupOptions = list
          }else{
            this.$message.error(response.data.msg)
          }
        })
      }
    }
  }
</script>
